(function($, yulu) {
    if ($ === undefined) {
        if (console && console.error) {
            console.error("!!!yulu library required jQuery support!!!");
        }
        return;
    }
    if (yulu === undefined) {
        if (console && console.error) {
            console.error("!!!yulu ajax library required yulu.core !!!");
        }
        return;
    }
    $.ajaxSetup({xhrFields:{withCredentials: true}})

    var defaultAjaxOptions = yulu("ajax.defaults");
    defaultAjaxOptions.cache = false;
    defaultAjaxOptions.type = "post";
    defaultAjaxOptions.dataType = "json";

    if (jQuery.prototype.serializeObject === undefined) {
        jQuery.prototype.serializeObject = function() {
            var obj = {};
            $.each(this.serializeArray(), function(index, param) {
                if (!(param.name in obj)) {
                    obj[param.name] = param.value;
                }
            });
            return obj;
        }
    }

    var ajax = yulu("ajax");
    ajax.getOptions = function(selector) {
        var $ele = $(selector);
        var options = yulu.core.getDataOptions(selector, "ajax");
        if (options.hasOwnProperty("data")) {
            if (typeof (options["data"]) === "string") {
                var data = {};
                var items = options["data"].split("&");
                $.each(items, function(index, str) {
                    if (str) {
                        var tmp = str.split("=");
                        data[tmp[0]] = tmp.length > 1 ? tmp[1] : "";
                    }
                });
                options["data"] = data;
            }
        }
        return $.extend({}, defaultAjaxOptions, options);
    }
})(window.jQuery, window.yulu);
